package com.lalosoft.misgastos.activities;

import java.sql.SQLException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Window;

import com.lalosoft.misgastos.R;
import com.lalosoft.misgastos.config.Constants;
import com.lalosoft.misgastos.config.GastosManager;

public class SplashActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.splash);
		new Handler().postDelayed(new Runnable() {
			
			@Override
			public void run() {
				if(GastosManager.getInstance(getApplicationContext()).isLogged()){
					Log.i("Splash", "Usuario logueado!");
					try {
						GastosManager.getInstance(getApplicationContext()).setCurrentAccount();
						Intent i = new Intent(getApplicationContext(), MainActivity.class);
						startActivity(i);
					} catch (SQLException e) {
						Log.e("Splash", "Error en recuperar cuenta: " + e.getMessage(), e);
					}
				} else {
					Log.i("Splash", "Usuario no logueado");
					Intent i = new Intent(getApplicationContext(), SettingsActivity.class);
					startActivity(i);
				}
				finish();				
			}
		}, Constants.LENGHT_SPLASH);
			}

}
